package cn.itcast.servlet;

import cn.itcast.domain.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;

/**
 * 查看所有学生
 */
@WebServlet("/findAllStudentServlet")
public class findAllStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      /*  //从系统文件中获取学生信息
        BufferedReader br = new BufferedReader(new FileReader("d:\\stu.txt"));
        //创建集合，将封装了学生信息的对象存进去
        ArrayList<Student> list = new ArrayList<>();
        //获取字符输入流中的数据
        String len;
        while ((len=br.readLine())!=null){
            //注意！！！创建对象的操作要在循环里完成，保证每一段读出来切割后封装的都是新的对象，不然会一致重新赋值这样
            Student student = new Student();
            String[] split = len.split(",");
            student.setName(split[0]);
            student.setAge(Integer.parseInt(split[1]));
            student.setScore(Integer.parseInt(split[2]));
            list.add(student);
        }
        System.out.println(list.size());
        //赋值完事之后，向页面写出
        resp.setContentType("text/html;charset=utf-8");
        for (Student student1 : list) {
            resp.getWriter().write(student1.getName()+","+student1.getAge()+","+student1.getScore());
            resp.getWriter().write("<br>");
        }*/
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
